package lingnan.cn.edu.Table;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import lingnan.cn.edu.BaseAndImpl.ItemService;
import lingnan.cn.edu.User.Orderinf;
import lingnan.cn.edu.service.ItemServiceImpl;

public class OrderinfTableModel extends AbstractTableModel{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6707710566849327621L;


	private String[] columnName = { "订单编号","餐品名", "数量", "单品总价" };
	 	
	
	private ItemService itemservice = new ItemServiceImpl();
	
	private List<Orderinf> orderinfs;
	
	public void query() {
		orderinfs = itemservice.query();
	}
	
	public void findOrder(int orderId) {
		orderinfs = itemservice.findOrder(orderId);
	}
	
	@Override
	public int getRowCount() {
		
		return orderinfs.size();
	}

	@Override
	public int getColumnCount() {
		return columnName.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Orderinf orderinf = orderinfs.get(rowIndex);
		if(columnIndex==0) {
			return orderinf.getOrderId();
		}else if(columnIndex==1) {
			return orderinf.getName();
		}else if(columnIndex==2) {
			return orderinf.getCount();
		}else if(columnIndex==3){
			return orderinf.getItemPrice();
		}else {
			return null;
		}

	}

	@Override
	public String getColumnName(int column) {
		return columnName[column];

	}

}
